import { Router } from 'express'
import { USER, STUDENT } from '../../db/model'
import { remove, transaction } from '../../db/dao'

const router = Router()

router.delete('/delete', (req, res) => {
  const { type, account } = req.body
  transaction(session => Promise.all([
    remove(USER, { account, identity: type }, { session }, true),
    remove(STUDENT, { account }, { session }, true)
  ])).then(() => {
    res.status(200).json({
      message: '删除成功',
      account
    })
  }).catch(() => {
    res.status(500).end()
  })
})

export default router
